package com.atguigu.bigdata.chapter05.transform;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @Author lzc
 * @Date 2022/9/2 10:26
 */
public class Flink06_Shuffle {
    public static void main(String[] args) {
        Configuration conf = new Configuration();
        conf.setInteger("rest.port", 2000);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
        env.setParallelism(2);
    
    
        env
            .fromElements(1, 10, 3, 6, 9, 11).setParallelism(1)
            //            .shuffle()
            .rebalance()  // 平均分布
            .print();
        
        try {
            env.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
/*

对数据再分区:
1. keyBy
    通过key双重hash再分区
        聚合必用
2. shuffle
    随机
3. rebalence
    平均
        有可能会跨TaskManager, 所以会走网络

4. rescale
    平均
        完全走的管道,  不经过网络, 效率更高



 */